#ifndef __C_PROC_SPINLOCK_H__
#define __C_PROC_SPINLOCK_H__

#include "std/std.h"
#include "arch/cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef VIEWS_SMP_ENABLED

typedef int spinlock_t;

#define SPINLOCK_INITIALIZER()				(-1)
#define DECLARE_SPINLOCK(lock)				spinlock_t lock = -1
#define DECLARE_PRIVATE_SPINLOCK(lock)		static spinlock_t lock = -1

void disable_preempt(spinlock_t *lock);
void enable_preempt(spinlock_t *lock);

#ifdef TEST_DBG_WIN32

#define spin_lock(lock)						do {} while (0)
#define spin_lock_irqsave(lock, flags)		do {} while (0)
#define spin_unlock(lock)					do {} while (0)
#define spin_unlock_irqrestore(lock, flags)	do {} while (0)
#define init_spinlock(lock)					do { *(lock) = 0; } while (0)

#else

#define spin_lock(lock)						do { disable_preempt(lock); } while (0)
#define spin_lock_irqsave(lock, flags)		do { local_irq_save(flags); disable_preempt(lock); } while (0)

#define spin_unlock(lock)					do { enable_preempt(lock); } while (0)
#define spin_unlock_irqrestore(lock, flags)	do { enable_preempt(lock); local_irq_restore(flags); } while (0)

#define init_spinlock(lock)					do { *(lock) = 0; } while (0)

#endif

#else

// SMP version

#endif

#ifdef __cplusplus
}
#endif
#endif
/* EOF */
